package cn.tanglong.feign.clinets;

import cn.tanglong.domain.User;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class UserFeignClientFallFactory implements FallbackFactory<UserFeignClinet>{

    // throwable:异常数据
    @Override
    public UserFeignClinet create(Throwable throwable) {
        return new UserFeignClinet(){
            // 这个方法就是降级方法
            @Override
            public User getById(Long id) {
                // 打印错误
                throwable.printStackTrace();
                return new User(-1L, "", "出现错误！");
            }
        };
    }
}
